<template>
  <div>
    <!-- 条件搜托条 -->
    <div class="topSearch">
      <div class="leftBox">
      <div class="searchbox">
      <em>缴费方案名称：</em>
      <el-select v-model="searchBox.programme" @change="changPJ" size="small" placeholder="请选择项目" style="width:150px">
        <el-option v-for="pj in searchBox.projectListG" :key="pj.projectId" :label="pj.projectName" :value="pj.projectId"></el-option>
      </el-select>
      </div>
      <div class="searchbox">
      <em>年级：</em>
      <el-select v-model="searchBox.grade" size="small" @change="gradeChange" style="width:100px"  placeholder="请选择年级" >
        <el-option label="全部" value=""></el-option>
        <el-option v-for="grade in searchBox.gradeList" :key="grade.gradeId" :label="grade.gradeName" :value="grade.gradeId"> </el-option>
      </el-select>
      </div>
      <div class="searchbox">
      <em>班级：</em>
      <el-select v-model="searchBox.class" size="small" style="width:100px" :disabled="searchBox.studentSource=='Sign'" placeholder="请选择年级" >
        <el-option label="全部" value=""></el-option>
        <el-option v-for="cla in searchBox.classList" :key="cla.classId" :label="cla.className" :value="cla.classId"> </el-option>
      </el-select>
      </div>
      <div class="searchbox">
      <em>学生姓名/身份证号：</em>
      <el-input v-model="searchBox.studentName" size="small" style="width:200px" placeholder="请输入学生姓名/身份证号"></el-input>
      </div>
      <div class="searchbox">
        <el-button type="primary" @click="getList" size="mini">查询</el-button>
        <el-button type="primary" @click="piliangbulu" size="mini">批量补录</el-button>
      </div>
      </div>
      <!-- <div class="rightBox">
         <el-button type="primary" size="mini" @click="dialogFormVisible1=true">批量补录</el-button>
          <el-button type="primary" size="mini">批量打印数据</el-button>
      </div> -->
      <div class="clear"></div>
    </div>


    <!-- 列表内容↓ -->
    <div class="contentBox">
      <el-table :data="supplementList" :header-cell-style="headClass" border stripe style="width: 100%" height="90%" @selection-change="handleSelectionChange">
          <!-- <el-table-column fixed type="selection" width="55"></el-table-column> -->
          <el-table-column prop="projectName" label="缴费方案名称" width="200"></el-table-column>
          <el-table-column label="方案状态">
            <template slot-scope="scope">
              <span v-if="scope.row.projectState=='Draft'">草稿</span>
              <span v-if="scope.row.projectState=='UnPublished'">未发布</span>
              <span v-if="scope.row.projectState=='Published'">已发布</span>
              <span v-if="scope.row.projectState=='StopUse'">停用</span>
            </template>
          </el-table-column>
          <el-table-column prop="schoolName" label="所在校区" width="200"></el-table-column>
          <el-table-column prop="gradeName" label="就读年级"></el-table-column>
          <el-table-column label="班级" width="120">
            <template slot-scope="scope">
              <span v-if="scope.row.className==null||scope.row.className==undefined||scope.row.className==''">未设置班级</span>
              <span v-else>{{scope.row.className}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="studentName" label="学生姓名" width="120">
            <!-- <template slot-scope="scope">
              <strong style="color:#ff6910; font-size:16px;">{{scope.row.studentName}}</strong>
            </template> -->
          </el-table-column>
          <el-table-column prop="identityCardNumber" label="身份证号" width="200"></el-table-column>
          <!-- <el-table-column prop="stuType" label="学生类型"></el-table-column> -->
          <el-table-column label="应缴金额">
            <template slot-scope="scope">
              <span v-if="scope.row.payableMoney==''||scope.row.payableMoney==null||scope.row.payableMoney==undefined">0.00</span>
              <!-- <span :class="{fuFont:parseFloat(scope.row.payableMoney?scope.row.payableMoney:0).toFixed(2)*1000<0}" v-else>{{scope.row.payableMoney|moneyStyle}}</span> -->
              <span :class="{fuFont:parseFloat(scope.row.payableMoney?scope.row.payableMoney:0).toFixed(2)*1000<0}" v-else>{{yinshouMoney(scope.row)|moneyStyle}}</span>
            </template>
          </el-table-column>
          <el-table-column label="实收金额">
            <template slot-scope="scope">
              <span v-if="scope.row.paidMoney==''||scope.row.paidMoney==null||scope.row.paidMoney==undefined">0.00</span>
              <span :class="{fuFont:parseFloat(scope.row.paidMoney?scope.row.paidMoney:0).toFixed(2)*1000<0}" v-else>{{scope.row.paidMoney|moneyStyle}}</span>
              <!-- <span :class="{fuFont:parseFloat(scope.row.paidMoney?scope.row.paidMoney:0).toFixed(2)*1000<0}" v-else>{{ shishouMoney(scope.row)|moneyStyle}}</span> -->
            </template>
          </el-table-column>
          <el-table-column prop="tuitionMoney" label="减免总金额">
            <template slot-scope="scope">
              <span style="color:#e8851e;" v-if="scope.row.tuitionMoney==''||scope.row.tuitionMoney==null||scope.row.tuitionMoney==undefined">0.00</span>
              <span style="color:#e8851e;" :class="{fuFont:parseFloat(scope.row.tuitionMoney?scope.row.tuitionMoney:0).toFixed(2)*1000<0}" v-else>{{scope.row.tuitionMoney|moneyStyle}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="paynot" label="欠缴金额">
            <template slot-scope="scope">
              <!-- <span>{{scope.row.payableMoney-scope.row.paidMoney-scope.row.tuitionMoney}}</span> -->
              <span :class="{fuFont:parseFloat(qianjiao(scope.row)).toFixed(2)*1000<0}" >{{qianjiao(scope.row)}}</span>
            </template>
          </el-table-column>
          <el-table-column fixed="right" width="120" label="操作">
            <template slot-scope="scope">
              <el-button @click="supplement(scope.row)" type="primary" size="mini">补录</el-button>
              <!-- <el-button v-if="scope.row.paymentState=='PaidUp'||scope.row.paymentState=='UnPaidUp'" @click="printing(scope.row)" type="text" size="small">打印数据</el-button> -->
            </template>
          </el-table-column>
      </el-table>
      <div class="paging">
        <el-pagination background layout="total, prev, pager, next" @current-change="handleCurrentChange" :current-page.sync="pageIndex" :total="pageAll"></el-pagination>
      </div>

    </div>


    <!-- 弹层内容↓ -->
    <el-dialog title="补录信息" :visible.sync="dialogFormVisible" width="80%">
      <div class="layerMaxHeight layerBox">
        <div class="baseMessage">
            <ul>
              <li><em>姓名：</em><strong style="color:#ff6a00; font-size:16px;">{{userData.studentName}}</strong></li>
              <li><em>年级：</em>{{userData.gradeName}}</li>
              <li><em>班级：</em>{{userData.className|classStyle}}</li>
              <li><em>缴费类型：</em>{{userData.paymentCategoryName}}</li>
              <li><em>欠缴金额：</em>{{userData.qianjiao}}</li>
            </ul>
          </div>
      <el-form :model="form" label-width="150px" size="small">
        <el-form-item label="请选择补录时间">
          <el-date-picker v-model="form.time" value-format="yyyy-MM-dd HH:mm:ss" :picker-options="pickerOptionsEnd" type="datetime" placeholder="选择日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="补录金额">
          <div class="rightCon">
            <div class="payListBox">
              <dl v-for="(a,index) in form.itemList" :key="index">
                <dt>{{a.itemName}}</dt>
                <dd><el-input-number v-model="a.money" :class="{ 'fu' :parseFloat(a.money?a.money:0).toFixed(2)*1000<0 }" :precision="2" :max="9999999999999" :controls="false" :step="0.01"></el-input-number></dd>
              </dl>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="请填写方式和金额">
          <div class="rightCon">
            <div class="payListBox">
              <dl>
                <dt>刷卡</dt>
                <dd><el-input-number v-model="form.cardMoney" :class="{ 'fu' :parseFloat(form.cardMoney?form.cardMoney:0).toFixed(2)*1000<0 }" :precision="2" :controls="false" :max="9999999999999" :step="0.01"></el-input-number></dd>
              </dl>
              <dl>
                <dt>现金</dt>
                <dd>
                  <el-input-number v-model="form.cashMoney" :class="{ 'fu' :parseFloat(form.cashMoney?form.cashMoney:0).toFixed(2)*1000<0 }" :precision="2" :controls="false" :max="9999999999999" :step="0.01"></el-input-number>
                  </dd>
              </dl>
              <dl>
                <dt>转账</dt>
                <dd><el-input-number v-model="form.transferMoney" :class="{ 'fu' :parseFloat(form.transferMoney?form.transferMoney:0).toFixed(2)*1000<0 }" :precision="2" :controls="false" :max="9999999999999" :step="0.01"></el-input-number></dd>
              </dl>
              <dl>
                <dt>其它方式</dt>
                <dd><el-input-number v-model="form.otherMoney" :class="{ 'fu' :parseFloat(form.otherMoney?form.otherMoney:0).toFixed(2)*1000<0 }" :precision="2" :controls="false" :max="9999999999999" :step="0.01"></el-input-number></dd>
              </dl>
              <dl>
                <dt>合计</dt>
                <dd>{{parseFloat((parseFloat(form.cardMoney?form.cardMoney:0).toFixed(2)*1000+parseFloat(form.cashMoney?form.cashMoney:0).toFixed(2)*1000+parseFloat(form.transferMoney?form.transferMoney:0).toFixed(2)*1000+parseFloat(form.otherMoney?form.otherMoney:0).toFixed(2)*1000)/1000).toFixed(2)|kexuejishu}}</dd>
              </dl>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="是否寄宿" style=" width:30%; display:inline-block;">
          <el-tag v-if="userData.isResidence=='1'||removeSpaces(userData.isResidence)=='是'">是</el-tag>
          <el-tag v-else type="info">否</el-tag>
        </el-form-item>
        <el-form-item label="是否军训"  style=" width:30%; display:inline-block;">
          <el-tag v-if="userData.isMilitaryTraining =='1'||removeSpaces(userData.isMilitaryTraining )=='是'">是</el-tag>
          <el-tag v-else type="info">否</el-tag>
        </el-form-item>
        <el-form-item label="是否体检"  style=" width:30%; display:inline-block;">
          <el-tag v-if="userData.isPhysicalExamination =='1'||removeSpaces(userData.isPhysicalExamination )=='是'">是</el-tag>
          <el-tag v-else type="info">否</el-tag>
        </el-form-item>
        <el-form-item label="补录说明">
          <el-input type="textarea" :rows="5" maxlength="200" show-word-limit placeholder="请输入内容" v-model="form.remark"></el-input>
        </el-form-item>
      </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="saveMes">确 定</el-button>
      </div>
    </el-dialog>

    <!--------- 批量补录 --------->
    <el-dialog title="批量补录信息" :visible.sync="dialogFormVisible1">
      <div class="layerMaxHeight">
        <div class="layerBox">

      <el-form :model="form1" label-width="120px" size="small">
        <el-form-item label="模板下载">
          <el-select v-model="form1.select" placeholder="请先选择缴费方案">
            <el-option v-for="item in form1.payTypeList" :key="item.projectId" :label="item.projectName" :value="item.projectId"></el-option>
          </el-select>
          <el-button type="primary" size="small" @click="exportTemplate">导出模板</el-button>
          <div class="Explain">
            <h4><span>备注</span></h4>
            <ul>
              <li>请先选择缴费方案再导出模板！</li>
            </ul>
          </div>
        </el-form-item>
        <el-form-item label="导入">
          <!-- <el-button type="primary">上传文件</el-button> -->
          <div class="selfButton"><input type="file" id="fileMode" accept=".xls" @change="upMode" />选择Excel</div>
        </el-form-item>
        <el-form-item label="下载失败模板" v-if="showFailUrl">
          <el-button type="primary" @click="downLoadFail">点击下载失败模板</el-button>
        </el-form-item>

      </el-form>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible1 = false">取 消</el-button>
      </div>
    </el-dialog>



     <div class="printBox" id="printBox" v-if="dialogFormVisible2">
      <!-- <span class="close"  v-if="closebtshow" @click="closeImgLayer"><i class="el-icon-circle-close"></i></span> -->
      <div class="invoice" id="invoice">
        <span class="close"  v-if="closebtshow" @click="closeImgLayer"><i class="el-icon-circle-close"></i></span>
            <div class="invoiceTop">
              <h3>
                <span class="logo"><img src="@/assets/img/zpLogo_03.png"></span>收款专用收据<em>NO.{{detailMesDY.serialNumber}}</em>
                <div class="clear"></div>
                </h3>

              <P><span>姓名:{{detailMesDY.studentName}}</span><span>年级：{{detailMesDY.gradeName}}</span><span>班级:<em v-if="detailMesDY.className==null||detailMesDY.className==''||detailMesDY.className==undefined">未设置分班</em><em v-else>{{detailMesDY.className}}</em></span><span>联系方式:{{detailMesDY.mobile}}</span><span>收款日期:{{timeSet.year}}年{{timeSet.mounth}}月{{timeSet.day}}日</span></P>
            </div>
            <div class="invoiceCenter">
              <div class="fakeTable">
                <div class="fakeTableHeader">
                  <div style="flex:4"><em>项目</em></div>
                  <div style="flex:2"><em>数量</em></div>
                  <div style="flex:2"><em>单价</em></div>
                  <div style="flex:9">
                    <div><em>金额</em></div>
                    <div><span>佰</span><span>拾</span><span>万</span><span>仟</span><span>佰</span><span>拾</span><span>元</span><span>角</span><span>分</span></div>
                  </div>
                  <div style="flex:2"><em>备注</em></div>
                </div>
                <div class="fakeTableBody">
                  <div class="fakeTableBodyN" v-for="(a,index) in detailMesDY.itemList" v-show="detailMesDY.isDetailed==1" :key="index">
                    <div style="flex:4"><em>{{a.itemName}}</em></div>
                    <div style="flex:2"><em>1</em></div>
                    <div style="flex:2"><em>{{a.money}}</em></div>
                    <div style="flex:9">
                      <div>
                        <span v-for="(b,index2) in 9-a.listMoney.length" :key="'B'+index2"></span>
                        <span v-for="(c,index3) in a.listMoney" :key="'C'+index3">{{c}}</span>
                      </div>
                    </div>
                    <div style="flex:2"></div>
                  </div>
                  <div class="fakeTableBodyN" v-if="tuifei">
                    <div style="flex:4"><em>减免金额</em></div>
                    <div style="flex:2"><em>1</em></div>
                    <div style="flex:2"><em>{{jianmianNum}}</em></div>
                    <div style="flex:9">
                      <div>
                        <span v-for="(b,index4) in 9-jianmianList.length" :key="'B'+index4"></span>
                        <span v-for="(c,index5) in jianmianList" :key="'C'+index5">{{c}}</span>
                      </div>
                    </div>
                    <div style="flex:2"></div>
                  </div>
                  <div class="fakeTableBodyN">
                    <div style="flex:6;">
                      <em v-if="detailMesDY.isDetailed!=1">
                        <font style="display: inline-block; width:66%;">收费项</font><font style="display: inline-block; width:35%;">1</font>
                      </em>
                      <em v-else></em>
                    </div>
                    <div style="flex:2;"><em>合计</em></div>
                    <div style="flex:9;">
                      <div>
                        <span v-for="(d,index4) in 9-totalMoney.length" :key="'D'+index4"></span>
                        <span v-for="(e,index5) in totalMoney" :key="'E'+index5">{{e}}</span>
                      </div>
                    </div>
                    <div style="flex:2;"></div>
                  </div>
                  <div class="fakeTableBodyN">
                    <div style="flex:17;">
                      <em ref="daxie" id="daxie" style="text-align:left; padding:10px;">金额大写(大写):
                        <!-- <i v-for="(f,index6) in 9-totalMoney.length" :key="'F'+index6"></i>
                        <i v-for="(g,index7) in totalMoney" :key="'G'+index7">{{g|newmoney}}{{(index7)}}</i> -->
                        <i>{{totalMoney[0]|newmoney}}佰</i>
                        <i>{{totalMoney[1]|newmoney}}拾</i>
                        <i>{{totalMoney[2]|newmoney}}万</i>
                        <i>{{totalMoney[3]|newmoney}}仟</i>
                        <i>{{totalMoney[4]|newmoney}}佰</i>
                        <i>{{totalMoney[5]|newmoney}}拾</i>
                        <i>{{totalMoney[6]|newmoney}}元</i>
                        <i>{{totalMoney[7]|newmoney}}角</i>
                        <i>{{totalMoney[8]|newmoney}}分</i>
                        <!-- <i>拾</i><i>万</i><i>仟</i><i>佰</i><i>拾</i><i>元</i><i>角</i><i>分</i> -->
                      </em>
                      </div>
                    <div style="flex:2;"><em></em></div>
                  </div>
                  <div class="fakeTableBodyN">
                    <div style="flex:19; border-top:1px solid #000;">
                      <em style="text-align:left; padding:10px;">
                        <i>收款方式:</i>
                        <i>现金<font v-if="detailMesDY.cashMoney=='1'" style=" font-weight:bold; font-size: 22px; line-height: 0.7em; text-indent: -0.2em;">√</font><font v-else></font></i>
                        <i>转账<font v-if="detailMesDY.transferMoney=='1'" style=" font-weight:bold; font-size: 22px; line-height: 0.7em; text-indent: -0.2em;">√</font><font v-else></font></i>
                        <i>刷卡<font v-if="detailMesDY.cardMoney=='1'" style=" font-weight:bold; font-size: 22px; line-height: 0.7em; text-indent: -0.2em;">√</font><font v-else></font></i>
                        <i>微信公众号<font v-if="detailMesDY.onLineMoney=='1'||detailMesDY.onLineMoney==null" style=" font-weight:bold; font-size: 22px; line-height: 0.7em; text-indent: -0.2em;">√</font><font v-else></font></i>
                        <i>其他方式<font v-if="detailMesDY.otherMoney=='1'" style=" font-weight:bold; font-size: 22px; line-height: 0.7em; text-indent: -0.2em;">√</font><tt v-else></tt></i>
                      </em>
                      </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="imgBox" v-if="detailMesDY.sealUrl">
              <img class="yin" :src="$store.state.userModule.phurl+detailMesDY.sealUrl">
            </div>
            <div class="invoiceBottom">
              <p><span>开票单位:{{schoolName}}</span><span style="float:right">收款人:<em v-if="detailMesDY.onLineMoney=='1'||detailMesDY.onLineMoney==null">线上收款</em><em v-else>线下收款</em></span></p>
            </div>
          </div>
      <div class="bts" v-if="btshow"><el-button type="primary" @click="printImg" style="width:120px">打印</el-button></div>
    </div>






    <!-- 弹层结束↑ -->



  </div>
</template>

<script>
export default {
  data() {
    return {
      userData:{},
      ccc:'补录内容',
      pageIndex:1,
      pageAll:0,
      tuifei:true,
      load:false,
      saveState:false,
      searchBox:{
        programme:'',
        schollRegion:'',
        schollRegionList:[],
        grade:'',
        gradeList:[],
        class:'',
        classList:[],
        studentName:'',
        cardID:'',
        studentSource:'',
        projectListG:[]
      },
      supplementList:[],
      dialogFormVisible:false,
      dialogFormVisible1:false,
      dialogFormVisible2:false,
      showViewer:false,
      btshow:true,
      closebtshow:true,
      baseMes:{
        name:'张三',
        grade:'初一',
        type:'自费型',
        score:'500',
        scoreAdd:'12',
        scorefor:'5',
        moneny:'19000',
      },
      form: {
        proejctId:'',
        studentId:'',
        studentSource:'',
        time:'',
        itemList:[],
        cardMoney:0,
        cashMoney:0,
        transferMoney:0,
        otherMoney:0,
        remark:''
      },
      form1:{
        select:'',
        payTypeList:[]
      },
      frozenTime:'',
      detailMesDY:{
        grade:'一年级'
      },
      schoolName:'',
      jianmianList:[],
      jianmianNum:0,
      totalMoney:[],
      seid:'',
      timeSet:{
        year:'',
        mounth:'',
        day:''
      },
      failUrl:'',
      showFailUrl:false,
      pickerOptionsEnd:{
         disabledDate:time=>{
          return time.getTime() <= new Date(this.frozenTime).getTime();
        }
      }
    }
  },
  // 监视
  watch:{
    "searchBox.programme":function(v){
      if(v){
        this.getList();
      }
    },
    "searchBox.grade":function(v){
      if(v){
        this.getList();
      }
    },
    "searchBox.class":function(v){
      if(v){
        this.getList();
      }
    }
  },
  filters:{
    newmoney:function(val){
      var oldfont = "";
      if(!val)return '--';
      switch(val){
        case "0":
          oldfont = "零";
          break;
          case "1":
          oldfont = "壹";
          break;
          case "2":
          oldfont = "贰";
          break;
          case "3":
          oldfont = "叁";
          break;
          case "4":
          oldfont = "肆";
          break;
          case "5":
          oldfont = "伍";
          break;
          case "6":
          oldfont = "陆";
          break;
          case "7":
          oldfont = "柒";
          break;
          case "8":
          oldfont = "捌";
          break;
          case "9":
          oldfont = "玖";
          break;
          default:
          oldfont = "";
      }
      return oldfont;
    },
    moneyStyle(val){
      var nm = 0;
      nm = parseFloat(val).toFixed(2);
      return nm;
    },
    kexuejishu(val){
      if(/\d+\.?\d*e[\+\-]*\d+/i.test(val)) {    //正则匹配科学计数法的数字
          var zero = '0',                                    //
            parts = String(val).toLowerCase().split('e'), //拆分成系数和指数
            e = parts.pop(),//存储指数
            l = Math.abs(e), //取绝对值，l-1就是0的个数
            sign = e/l,          //判断正负
            coeff_array = parts[0].split('.');   //将系数按照小数点拆分
          if(sign === -1) {           //如果是小数
            val = zero + '.' + new Array(l).join(zero) + coeff_array.join('');   //拼接字符串，如果是小数，拼接0和小数点
          } else {
            var dec = coeff_array[1];
            if(dec) l = l - dec.length;  //如果是整数，将整数除第一位之外的非零数字计入位数，相应的减少0的个数
            val = coeff_array.join('') + new Array(l+1).join(zero);    //拼接字符串，如果是整数，不需要拼接小数点
          }
        }

        return val;
    },
    classStyle(val){
      if(!val) return "暂未设置班级";
      return val
    }
  },
  mounted() {
    this.getCondition();
  },
  computed:{

  },
  methods: {
    yinshouMoney(obg){
      var mny = obg.payableMoney;
      if(obg.isMilitaryTraining=="0"||obg.isMilitaryTraining=="否"){
        mny = (parseFloat(mny).toFixed(2)*1000 - parseFloat(obg.militaryTrainingMoney).toFixed(2)*1000) / 1000;
      }

      if(obg.isPhysicalExamination=="0"||obg.isPhysicalExamination=="否"){
        mny = (parseFloat(mny).toFixed(2)*1000 - parseFloat(obg.physicalExaminationMoney).toFixed(2)*1000) / 1000;
      }
      return mny;
    },
    // 字符串去空格
    removeSpaces(mes){
      if(!mes) return "0";
      return mes.replace(/\s*/g,"");
    },
    // 设置日期
    setDate(){
      var stime = new Date();
      var ftime = new Date(this.frozenTime);
      if((new Date(this.frozenTime).getFullYear()==new Date().getFullYear())&&(new Date(this.frozenTime).getMonth()==new Date().getMonth())&&(new Date(this.frozenTime).getDate()==new Date().getDate())){
        this.form.time =  new Date(stime.valueOf()+1*24*60*60*1000).getFullYear()+'-'+(new Date(stime.valueOf()+1*24*60*60*1000).getMonth()+1).toString().padStart(2,'0')+'-'+(new Date(stime.valueOf()+1*24*60*60*1000).getDate().toString().padStart(2,'0'))+" "+(new Date(stime.valueOf()+1*24*60*60*1000).getHours()).toString().padStart(2,'0')+":"+(new Date(stime.valueOf()+1*24*60*60*1000).getMinutes()).toString().padStart(2,'0')+":"+(new Date(stime.valueOf()+1*24*60*60*1000).getSeconds()).toString().padStart(2,'0');
      }else if(stime.getTime()<ftime.getTime()){
        this.form.time = new Date(ftime.valueOf()+1*24*60*60*1000).getFullYear()+'-'+(new Date(ftime.valueOf()+1*24*60*60*1000).getMonth()+1).toString().padStart(2,'0')+'-'+(new Date(ftime.valueOf()+1*24*60*60*1000).getDate().toString().padStart(2,'0'))+" "+(new Date(ftime.valueOf()+1*24*60*60*1000).getHours()).toString().padStart(2,'0')+':'+(new Date(ftime.valueOf()+1*24*60*60*1000).getMinutes()).toString().padStart(2,'0')+':'+(new Date(ftime.valueOf()+1*24*60*60*1000).getSeconds()).toString().padStart(2,'0');
      }else{
      this.form.time = stime.getFullYear()+'-'+(stime.getMonth()+1).toString().padStart(2,'0')+'-'+stime.getDate().toString().padStart(2,'0')+" "+stime.getHours().toString().padStart(2,'0')+':'+stime.getMinutes().toString().padStart(2,'0')+':'+stime.getSeconds().toString().padStart(2,'0');
      }
    },
    // 头部样式
    headClass:function(){
      return 'text-align: center;'
    },
    // 年级修改
    gradeChange:function(){
      this.searchBox.class='';
      this.getCondition();
    },
    // 欠缴
    qianjiao:function(obg){
      var numq = 0;
      numq = (parseFloat(obg.payableMoney==null?0:obg.payableMoney)*1000-parseFloat(obg.paidMoney==null?0:obg.paidMoney)*1000-parseFloat(obg.tuitionMoney==null?0:obg.tuitionMoney)*1000)/1000;
      if(obg.isMilitaryTraining=="0"||obg.isMilitaryTraining=="否"){
        numq = (parseFloat(numq).toFixed(2)*1000 - parseFloat(obg.militaryTrainingMoney).toFixed(2)*1000) / 1000;
      }

      if(obg.isPhysicalExamination=="0"||obg.isPhysicalExamination=="否"){
        numq = (parseFloat(numq).toFixed(2)*1000 - parseFloat(obg.physicalExaminationMoney).toFixed(2)*1000) / 1000;
      }
      return parseFloat(numq).toFixed(2);
    },
    // 缴费方案改变
    changPJ:function(event){
      this.searchBox.grade = "";
      for(var a=0,lenn = this.searchBox.projectListG.length;a<lenn;a++){
        if(this.searchBox.projectListG[a].projectId==event){
          this.searchBox.studentSource = this.searchBox.projectListG[a].studentSource;
        }
      }
    },
    //获取选择条件
    getCondition:function(){
      if(this.searchBox.grade!=''){
      this.$api.paymentOperation.GetSearchConditionBL(this.searchBox.grade).then(res=>{
        //console.log("获取班级查询条件",res);
        this.searchBox.classList = res.data.result.classList;
      })
      }else{
        this.$api.paymentOperation.GetSearchConditionBL().then(res=>{
        //console.log("获取查询条件",res);
          this.searchBox.gradeList = res.data.result.gradeList;
          this.searchBox.projectListG = res.data.result.projectList;
          this.searchBox.programme = res.data.result.projectList[0].projectId;
          this.form1.payTypeList = res.data.result.projectList;
          this.form1.select = res.data.result.projectList[0].projectId;
          this.searchBox.studentSource = res.data.result.projectList[0].studentSource;
          this.getList();
        })
      }
    },
    // 获取补录列表
    getList:function(){
      this.$api.paymentOperation.GetPayForStudentList(this.searchBox.programme,this.searchBox.studentSource,this.searchBox.grade,this.searchBox.studentName,this.searchBox.class,this.pageIndex).then(res=>{
        //console.log("获取补录列表",res)
        this.supplementList = res.data.result.list;
        this.pageIndex = res.data.result.page;
        this.pageAll = res.data.result.total;
        this.supplementList.forEach(e=>{
            if(e.isResidence=="0"||e.isResidence.replace(/\s*/g,"")=="否"){
              e.payableMoney = (parseFloat(e.payableMoney).toFixed(2)*1000-parseFloat(e.boarderMoney).toFixed(2)*1000)/1000
            }
          })
          this.load = true;
      })
    },
    // 获取补录数据详情
    supplement:function(val){
      console.log(val);
      this.userData = val;
      this.userData.qianjiao = this.qianjiao(val);
      this.schoolName = val.schoolName;
      this.dialogFormVisible=true;
      this.baseMes = val;
      this.form.remark="";
      this.form.itemList=[];
      this.form.cardMoney = 0;
      this.form.cashMoney = 0;
      this.form.transferMoney = 0;
      this.form.otherMoney = 0;
      this.$api.paymentOperation.GetPayForStudentDetail(val.projectId,val.studentId,val.schoolId,val.sectionId,val.gradeId,val.studentSource,val.paymentCategory).then(res=>{
        //console.log("获取单个补录详情",res)
        this.frozenTime = res.data.result.frozenTime;
        this.setDate();
        this.form.itemList = res.data.result.itemList;
        this.form.projectId = val.projectId;
        this.form.studentId= val.studentId;
        this.form.studentSource=val.studentSource;
        if(res.data.result.isSupplement == "Y"){
          for(var a of this.form.itemList){
            a.money = parseFloat(0).toFixed(2);
          }
        }
      })
    },
    // 表格选中
    handleSelectionChange:function(val){
      console.log(val);
    },
    // 保存补录
    saveMes:function(){
      if(this.$store.state.userModule.btPut=='1'){
        return;
      }
      if(this.form.time==""){
        this.$message({
          message:'请选择补录时间！',
          type:'warning'
        })
        return;
      }
      if((parseFloat(this.form.cardMoney).toFixed(2)+parseFloat(this.form.cashMoney).toFixed(2)+parseFloat(this.form.transferMoney).toFixed(2)+parseFloat(this.form.otherMoney).toFixed(2))==0){
        this.$message({
          message:'请输入金额进行补录！',
          type:'warning'
        })
        return;
      }

      var buluzj = 0;
      for(var i=0,len = this.form.itemList.length;i<len;i++){
        buluzj += parseFloat( this.form.itemList[i].money).toFixed(2)*1000;
      }
      var allNum =(parseFloat(this.form.cardMoney).toFixed(2)*1000+parseFloat(this.form.cashMoney).toFixed(2)*1000+parseFloat(this.form.transferMoney).toFixed(2)*1000+parseFloat(this.form.otherMoney).toFixed(2)*1000)
      if(allNum!=buluzj){
        this.$message({
          message:'补录金额和各方式合计金额不相同',
          type:'warning'
        })
        return;
      }
      if(allNum>parseFloat(this.userData.qianjiao).toFixed(2)*1000){
        this.$message({
          message:'各方式合计金额不能大于欠缴金额',
          type:'warning'
        })
        return;
      }
      // this.form.itemList = JSON.stringify(this.form.itemList);
      // this.saveState = true;
      this.$store.commit('stopButton',"1")
      this.$api.paymentOperation.CheckingSupplement(this.form.projectId,this.form.studentId).then(res=>{
        console.log(res);
        if(res.data.result){


      this.$api.paymentOperation.SaveSupplement(this.form.projectId,this.form.studentId,this.form.time,this.form.studentSource,this.form.itemList,this.form.cardMoney,this.form.cashMoney,this.form.transferMoney,this.form.otherMoney,this.form.remark).then(res=>{
        //console.log("保存补录返回",res);
        if(res.data.status=='SUCCESS'){
          this.$message({
            message:'保存补录成功',
            type:'success'
          })
          this.seid = res.data.result
          this.$store.commit('stopButton','-1')
          this.$confirm('是否立刻打印收据？','提示',{
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(()=>{
            this.printing(this.form);
            this.form.itemList = [];
            this.form.projectId = '';
            this.form.studentId= '';
            this.form.studentSource='';
            this.form.time = ''
            this.form.remark = '';
            this.form.cardMoney = 0;
            this.form.cashMoney = 0;
            this.form.transferMoney = 0;
            this.form.otherMoney = 0;
            this.dialogFormVisible = false;
          }).catch(()=>{
            this.$message({
              type: 'info',
              message: '已取消打印'
            });
            this.getList();
            this.form.itemList = [];
            this.form.projectId = '';
            this.form.studentId= '';
            this.form.studentSource='';
            this.form.time = ''
            this.form.remark = '';
            this.form.cardMoney = 0;
            this.form.cashMoney = 0;
            this.form.transferMoney = 0;
            this.form.otherMoney = 0;
            this.dialogFormVisible = false;
          })

          // this.getList();
        }
      })
      }else{
        this.$message({
          message:'该生未缴纳特训费！',
          type:'warning'
        })
        this.$store.commit('stopButton','-1')
        return;
      }
      })
    },
    // 打印收据
    printing:function(val){
      this.jianmianList = [];
      this.detailMesDY = {};
      this.tuifei = true;
      this.$api.paymentOperation.PrintingSupplementReceipt(val.projectId,val.studentId,this.seid).then(res=>{
        //console.log("打印返回",res);
        this.detailMesDY = res.data.result;
        if(res.data.result.tuitionMoney==null||res.data.result.tuitionMoney==undefined||res.data.result.tuitionMoney==""||parseFloat(res.data.result.tuitionMoney).toFixed(2)*1000==0){
          this.tuifei = false;
        }
        // var riqi = new Date();
        // this.timeSet.year = riqi.getFullYear();
        // this.timeSet.mounth = riqi.getMonth();
        // this.timeSet.day = riqi.getDate();
        var dateListN = this.detailMesDY.date.split("-");
        this.timeSet.year = dateListN[0];
        this.timeSet.mounth = dateListN[1];
        this.timeSet.day = dateListN[2].slice(0,2);
        this.setMoneys();
        this.dialogFormVisible2 = true;

      })
    },
    printImg(){
      this.btshow = false;
      setTimeout(function(){
        window.print(document.getElementById("printBox"));
      },1000)
    },
    closeImgLayer:function(){
      this.detailMesDY = {};
      this.totalMoney = [];
      this.jianmianList = [];
      this.dialogFormVisible2 = false;
      this.btshow = true;
      this.getList();
    },

    // TODO:设置数字
    setMoneys:function(){
      var that = this;
      that.jianmianList = [];
      var newList = new Array();
      var tNum = 0;
      that.detailMesDY.itemList.forEach(function(val,index){
        that.detailMesDY.itemList[index].money = (parseFloat(val.money).toFixed(2)*1000)/1000;
        that.detailMesDY.itemList[index].listMoney = [];
        tNum += parseFloat(val.money).toFixed(2)*1000;
        var list = new Array();
        var arr = parseFloat(val.money).toFixed(2).split('');
        for(var i=0,len = arr.length;i<len;i++){
          list.push(arr[i]);
        }
        that.detailMesDY.itemList[index].listMoney = that.dropListE('.',list);
      })
      that.jianmianNum = parseFloat(that.detailMesDY.tuitionMoney==null?0:parseFloat(that.detailMesDY.tuitionMoney).toFixed(2)*1000>0?that.detailMesDY.tuitionMoney:-(that.detailMesDY.tuitionMoney)).toFixed(2);
      var allNum = (tNum-parseFloat(that.detailMesDY.tuitionMoney==null?0:parseFloat(that.detailMesDY.tuitionMoney).toFixed(2)*1000>0?that.detailMesDY.tuitionMoney:-(that.detailMesDY.tuitionMoney)).toFixed(2)*1000)/1000;
      that.detailMesDY.tuitionMoney = parseFloat(that.detailMesDY.tuitionMoney==null?0:parseFloat(that.detailMesDY.tuitionMoney).toFixed(2)*1000>0?that.detailMesDY.tuitionMoney:-(that.detailMesDY.tuitionMoney)).toFixed(2).split('');
      for(var p=0,lenn = that.detailMesDY.tuitionMoney.length;p<lenn;p++){
        that.jianmianList.push(that.detailMesDY.tuitionMoney[p]);
      }
      that.jianmianList = that.dropListE('.',that.jianmianList);
      // var allNum = (tNum-parseFloat(that.detailMesDY.tuitionMoney==null?0:-(that.detailMesDY.tuitionMoney)).toFixed(2)*1000)/1000;
      // that.totalMoney = that.dropListE('.',parseFloat(allNum).toFixed(2).split(''));
      that.totalMoney = that.dropListE('.',(parseFloat(allNum).toFixed(2)*1000>0?allNum:-(allNum)).toFixed(2).split(''));
      var lastIndex = 9-that.totalMoney.length;
      for(var a=0,lenn =lastIndex;a<lenn;a++){
        that.totalMoney.unshift("");
      }
      // console.log(lastIndex);
      // console.log(that.detailMesDY.itemList);
      // console.log(that.totalMoney);
      // console.log(that.jianmianList);
    },
    // TODO:数组删除
    dropListE:function(str,arr){
      var index = arr.indexOf(str);
      arr.splice(index,1);
      return arr;
    },
    // 批量补录————导出模板
    exportTemplate:function(){
      this.$api.paymentOperation.ExportTemplate(this.form1.select).then(res=>{
        //console.log("导出模板",res);
        if(res.data.status=='SUCCESS'){
          window.open(res.data.result);
        }
      })
    },
    // 分页页面切换
    handleCurrentChange:function(val){
      this.pageIndex = val;
      this.getList();
    },
    // 关闭单据层
    closeReceipt(){
      this.dialogFormVisible2 = false;
      this.getList();
    },
    piliangbulu:function(){
      this.dialogFormVisible1 =! this.dialogFormVisible1;
      this.showFailUrl = false;
    },
    // 上传批量附件
    upMode:function(){
      var that = this;
      var newfile = document.getElementById("fileMode").files[0];
      //console.log(newfile.type);
      if(!newfile){
        that.$message({
          message:'请上传导入文件！',
          type: 'warning'
        })
        return;
      }
      var params = new FormData();
        params.append("file",newfile);
        var url = '/server/supplement/import/data';
        that.$qinqiu.post(url,params,{headers:{'Content-Type':'multipart/form-data'}}).then(res=>{
          //console.log("上传模板",res);
          if(res.data.status=="SUCCESS"){
            // that.$message({
            //   message:'导入成功！',
            //   type: 'success'
            // })
            if(res.data.result.result=='Y'){
              that.$message({
                message:'全部导入成功！',
                type: 'success'
              })
            }else{
              that.$message({
                message:'导入失败'+res.data.result.errorCount+'条',
                type: 'error'
              })
              that.showFailUrl = true;
              that.failUrl = res.data.result.url;
            }
            that.ExamRoomSetShow =false
            that.getExamRoomList()
          }else{
            that.$message({
              message:'导入失败',
              type: 'warning'
            })
          }
        }).catch(error=>{
          //console.log(error)
        })

    },
    // 下载错误模板
    downLoadFail:function(){
      window.open(this.failUrl);
    }
  }
}
</script>
<style scoped>
.fu{ border: 1px solid #F30;}
</style>
